package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByMoblie(String moblie) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        QueryWrapper<User> qw = queryWrapper.eq("mobile", moblie);

        return userMapper.selectOne(qw);
    }

    @Override
    public Long save(User user) {
          userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long id) {

        return userMapper.selectById(id);
    }

    @Override
    public User findByHuanxin(String huanxinId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        QueryWrapper<User> qw = queryWrapper.eq("hx_user", huanxinId);
        return userMapper.selectOne(qw);
    }


}
